import axios from './request'

export function getUsersList({search, page, pagesize}){
    const params = []
    if (search) {
        params.push('search'+'='+search)
    }
    if (page) {
        params.push('page'+'='+page)
    }
    if (pagesize) {
        params.push('pagesize'+'='+pagesize)
    }
    const paramsStr = params.join('&')
    // console.log(paramsStr);
    if (params.length !== 0) return axios.get('users'+'?'+paramsStr)
    return axios.get('users')
    
}

export function addUsersApi(data){
    return axios.post('users', data)
}

export function editUserStateApi(userInfo){
    return axios.patch('users/'+userInfo.id,{mg_state:userInfo.mg_state})
}

export function getUserInfo(id){
    return axios.get('users/' + id)
}

export function editUserInfoApi(userInfo){
    return axios.patch('users/'+userInfo.id, {email: userInfo.email, mobile: userInfo.mobile})
}

export function deleteUserApi(id){
    return axios.delete('users/'+id)
}

export function allocateRole(userInfo){
    return axios.patch('users/'+userInfo.id, {role_name_id: userInfo.role_name_id})
}